package Try;

import Try.FileUtils.FileUtil;
import com.sun.xml.internal.fastinfoset.tools.FI_DOM_Or_XML_DOM_SAX_SAXEvent;
import sun.text.resources.iw.FormatData_iw_IL;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class Main26 {
    public static void main(String[] args) throws IOException {
        File file = new File("C:\\Users\\ruanjie\\Desktop\\pictureList.txt");

        File file1 = new File("C:\\Users\\ruanjie\\Desktop\\cleanCloth.txt");

        File file2 = new File("C:\\Users\\ruanjie\\Desktop\\allPairs.txt");

        File file3 = new File("E:\\Picture\\clean_research\\cleanPha");

//        BufferedWriter writer = FileUtil.getBufferWriter(file1);
//
//        File[] files = file3.listFiles();
//        for (File f:files){
//            File[] files1 = f.listFiles();
//            for (File file4:files1){
//                File[] files2 = file4.listFiles();
//                for (File file5:files2){
//                    File[] files3 = file5.listFiles();
//                    for (File file6:files3){
//                        String l = file6.getAbsolutePath().replace("E:\\Picture\\clean_research\\cleanPha\\","");
//                        l = l.replaceAll("\\\\","/");
//                        System.out.println(l);
//                        writer.write(l);
//                        writer.newLine();
//                    }
//                }
//            }
//        }
//
//        writer.close();

        BufferedReader bufferedReader1 = FileUtil.getBufferReader(file1);

        List<String> list = new ArrayList<>();

        String line;
        while ((line = bufferedReader1.readLine())!=null){
            line = line.trim();

            File parent = new File((line)).getParentFile();

            list.add(parent.getAbsolutePath().replace("F:\\JavaProject\\",""));
        }

        BufferedReader bufferedReader = FileUtil.getBufferReader(file);
        BufferedWriter bufferedWriter = FileUtil.getBufferWriter(file2);

        while ((line = bufferedReader.readLine())!=null){
            line = line.trim();
            line = line.replace("pictures/","");
            String line_origin = new String(line);

            File f = new File(line);
            File parent = f.getParentFile();
            line = parent.getAbsolutePath().replace("F:\\JavaProject\\","");
            if (list.contains(line)){
                bufferedWriter.write(line_origin+ " " + line.replaceAll("\\\\","/") + "/p.jpg");
                bufferedWriter.newLine();
            }
        }

        bufferedWriter.close();


    }
}
